// 权限控制

import router from '@/router'
import store from '@/store'
const WHITE_LIST = ['/login', '/404'] // 白名单

router.beforeEach((to, from, next) => {
  if (store.state.user.token) {
    if (to.path === '/login') {
      next('/')
    } else {
      next()
      // 调用action函数 这个位置哦 !!!!!
      if (!store.state.user.userInfo.userId) {
        store.dispatch('user/fetchUserInfo')
      }
    }
  } else {
    if (WHITE_LIST.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})

